package com.leoman.controller.api;

import com.leoman.core.ErrorType;
import com.leoman.core.bean.Result;
import com.leoman.entity.CompanyUser;
import com.leoman.entity.CompanyUserGain;
import com.leoman.entity.VideoRecord;
import com.leoman.entity.vo.CompanyUserAuthVo;
import com.leoman.entity.vo.UserResumeVo;
import com.leoman.entity.vo.VideoVo;
import com.leoman.exception.*;
import com.leoman.service.AppUserService;
import com.leoman.service.CompanyUserGainService;
import com.leoman.service.CompanyUserService;
import com.leoman.service.VideoService;
import com.leoman.utils.JsonUtil;
import com.leoman.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 企业用户相关api
 * Created by 涂奕恒 on 2016/11/04 0018.
 */
@Controller
@RequestMapping(value = "api/companyUser")
public class CompanyUserApi {

    @Autowired
    private CompanyUserService companyUserService;

    @Autowired
    private CompanyUserGainService companyUserGainService;

    @Autowired
    private VideoService videoService;

    @Autowired
    private AppUserService appUserService;

    /**
     * @api {post} /api/companyUser/info 1、企业用户详情
     * @apiVersion 0.0.1
     * @apiName companyUser.info
     * @apiGroup companyUser
     *
     * @apiDescription 企业用户详情
     *
     * @apiParam   {Integer}  companyUserId                    企业用户ID            (必填)
     *
     * @apiSuccess {Object}   companyUserInfo
     * @apiSuccess {Integer}  companyUserInfo.id               id
     * @apiSuccess {String}   companyUserInfo.nickName         昵称
     * @apiSuccess {Integer}  companyUserInfo.type             类型，0=未申请认证，1=个人认证，2=企业认证
     * @apiSuccess {String}   companyUserInfo.mobile           联系方式
     * @apiSuccess {Integer}  companyUserInfo.checkStatus      审核状态，0=待审核，1=审核通过，2=审核失败
     * @apiSuccess {String}   companyUserInfo.checkFailReason  审核失败原因
     * @apiSuccess {Integer}  companyUserInfo.money            账户余额
     * @apiSuccess {Integer}  companyUserInfo.staticMoney      冻结金额
     * @apiSuccess {String}   companyUserInfo.createTime       注册时间
     * @apiSuccess {String}   companyUserInfo.updateTime       修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {
     *          "companyUserInfo": {
     *              "id": 14,
     *              "nickName": "老大",
     *              "type": 0,
     *              "mobile": "13872116519",
     *              "checkStatus": 0,
     *              "checkFailReason": "",
     *              "money": 2000,
     *              "staticMoney": 1000,
     *              "createTime": 1474600084564,
     *              "updateTime": 1474600084564
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public void info(HttpServletResponse response, Integer companyUserId) {
        try {
            CompanyUser companyUser = companyUserService.iFindOneByInfo(companyUserId);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successInfoApi(companyUser, "companyUserInfo"), "password", "sendTime", "sealStatus"));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/companyUser/checkInfo 2、企业用户认证信息
     * @apiVersion 0.0.1
     * @apiName companyUser.checkInfo
     * @apiGroup companyUser
     *
     * @apiDescription 企业用户认证信息
     *
     * @apiParam   {Integer}  companyUserId                        企业用户ID            (必填)
     *
     * @apiSuccess {Object}   companyUserAuth
     * @apiSuccess {Integer}  companyUserAuth.type                 类型，1=个人认证，2=企业认证
     * @apiSuccess {Integer}  companyUserAuth.name                 企业全称 or 姓名
     * @apiSuccess {String}   companyUserAuth.licenseNum           （企业）营业执照号码
     * @apiSuccess {String}   companyUserAuth.licenseUrl1           （企业）营业执照照片1
     * @apiSuccess {String}   companyUserAuth.licenseUrl2           （企业）营业执照照片2
     * @apiSuccess {String}   companyUserAuth.licenseUrl3           （企业）营业执照照片3
     * @apiSuccess {String}   companyUserAuth.paperType            （个人）证件类型，1=身份证，2=护照
     * @apiSuccess {String}   companyUserAuth.paperNum             身份证号 or 证件号码
     * @apiSuccess {String}   companyUserAuth.userPaperUrl         身份证照片 or 手持证件照片
     * @apiSuccess {String}   companyUserAuth.userName             （企业）负责人姓名
     * @apiSuccess {String}   companyUserAuth.mobile               联系方式
     * @apiSuccess {String}   companyUserAuth.email                （个人）电子邮箱
     * @apiSuccess {String}   companyUserAuth.address              （个人）联系地址
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {
     *          "companyUserAuth": {
     *              "type": 1,
     *              "name": "张莹共",
     *              "licenseNum": "",
     *              "licenseUrl": "",
     *              "paperType": 1,
     *              "paperNum": "421125199136524487",
     *              "userPaperUrl": "http:www.qq.com",
     *              "userName": "",
     *              "mobile": "15988563657",
     *              "email": "209365885@qq.com",
     *              "address": "武汉市洪山区野芷湖西路创意天地"
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/checkInfo", method = RequestMethod.POST)
    public void checkInfo(HttpServletResponse response, Integer companyUserId) {
        try {
            CompanyUserAuthVo companyUserAuthVo = companyUserService.iFindInfoByCompanyUserId(companyUserId);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successInfoApi(companyUserAuthVo, "companyUserAuth")));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        } catch (NoDataException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NO_DATA));
        }
    }

    /**
     * @api {post} /api/companyUser/sendCheckInfo 3、企业用户提交认证信息
     * @apiVersion 0.0.1
     * @apiName companyUser.sendCheckInfo
     * @apiGroup companyUser
     *
     * @apiDescription 企业用户提交认证信息
     *
     * @apiParam {Integer}  companyUserId                 企业用户ID                          (必填)
     * @apiParam {Integer}  type                          类型，1=个人认证，2=企业认证          (必填)
     * @apiParam {Integer}  name                          企业全称 or 姓名                    (必填)
     * @apiParam {String}   licenseNum                   （企业）营业执照号码
     * @apiParam {Stream}   url1                         （企业）营业执照照片1
     * @apiParam {Stream}   url2                         （企业）营业执照照片2
     * @apiParam {Stream}   url3                         （企业）营业执照照片3
     * @apiParam {String}   paperType                    （个人）证件类型，1=身份证，2=护照
     * @apiParam {String}   paperNum                      身份证号 or 证件号码
     * @apiParam {Stream}   basePicUrl                    身份证照片 or 手持证件照片
     * @apiParam {String}   userName                     （企业）负责人姓名
     * @apiParam {String}   mobile                        联系方式                            (必填)
     * @apiParam {String}   email                        （个人）电子邮箱
     * @apiParam {String}   address                      （个人）联系地址
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     * }
     */
    @RequestMapping(value = "/sendCheckInfo", method = RequestMethod.POST)
    public void sendCheckInfo(HttpServletResponse response, Integer companyUserId, CompanyUserAuthVo companyUserAuth, MultipartRequest multipartRequest) {
        try {
            companyUserService.iSaveCompanyAuthInfo(companyUserId, companyUserAuth, multipartRequest);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        } catch (AuthDataExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_AUTH_DATA_EXIST));
        }
    }

    /**
     * @api {post} /api/companyUser/gainList 4、企业用户收支明细列表
     * @apiVersion 0.0.1
     * @apiName companyUser.gainList
     * @apiGroup companyUser
     *
     * @apiDescription 企业用户收支明细列表
     *
     * @apiParam   {Integer}   companyUserId                  企业用户ID     （必填）
     * @apiParam   {Integer}   pageNum                        页码
     * @apiParam   {Integer}   pageSize                       每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.month                     年月
     * @apiSuccess {Integer}   list.gainList                  收支明细列表
     * @apiSuccess {Integer}   list.gainList.gainId           收支明细ID
     * @apiSuccess {String}    list.gainList.gainContent      收支明细内容
     * @apiSuccess {Integer}   list.gainList.gainMoney        收益金额
     * @apiSuccess {Integer}   list.gainList.gainCreateTime   收益获取时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "month" : "2016-11",
     *                  "gainList" : [
     *                      {
     *                          "gainId" : 6,
     *                          "gainContent" : "观看视频---测试视频008",
     *                          "gainMoney" : 4,
     *                          "gainCreateTime" : 1479093217553
     *                      },
     *                      {
     *                          "gainId" : 7,
     *                          "gainContent" : "观看视频---测试视频008",
     *                          "gainMoney" : 4,
     *                          "gainCreateTime" : 1479093217553
     *                      }
     *                  ]
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/gainList", method = RequestMethod.POST)
    public void gainList(HttpServletResponse response, Integer companyUserId, Integer pageNum, Integer pageSize) {
        try {
            Page<CompanyUserGain> page = companyUserGainService.iPageByCompanyUserId(companyUserId, pageNum, pageSize);
            Map<String, Object> dataMap = JsonUtil.fitting(page);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi(dataMap), "recordDate", "companyUser", "type", "content", "id", "createTime", "money"));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/companyUser/video/list 5、视频列表
     * @apiVersion 0.0.1
     * @apiName companyUser.videoList
     * @apiGroup companyUser
     *
     * @apiDescription 视频列表
     *
     * @apiParam   {Integer}   companyUserId              企业用户Id                （必填）
     * @apiParam   {Integer}   status                     视频状态，0=待审核，1=投放中，2=未投放，不传默认为全部
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    视频ID
     * @apiSuccess {Integer}   list.sendType              投放形式，1=一般形式，2=红包形式，3=其他形式，4=免费形式
     * @apiSuccess {Integer}   list.typeId                视频分类ID
     * @apiSuccess {String}    list.typeName              视频分类名称
     * @apiSuccess {Integer}   list.name                  视频名称
     * @apiSuccess {String}    list.cover                 封面图
     * @apiSuccess {String}    list.url                   视频链接
     * @apiSuccess {String}    list.duration              时长
     * @apiSuccess {String}    list.synopsis              简介
     * @apiSuccess {Integer}   list.playNum               播放量
     * @apiSuccess {String}    list.regionNames           投放区域名称，中间用英文逗号隔开
     * @apiSuccess {String}    list.startTime             开始时间
     * @apiSuccess {String}    list.endTime               结束时间
     * @apiSuccess {Integer}   list.price                 投放单价
     * @apiSuccess {Integer}   list.count                 投放次数
     * @apiSuccess {Integer}   list.isShopping            上架状态，0=下架，1=上架
     * @apiSuccess {Integer}   list.recordStatus          投放状态，0=未投放，1=投放中
     * @apiSuccess {Integer}   list.recordContent         投放信息
     * @apiSuccess {Integer}   list.checkStatus           审核状态，0=待审核，1=审核通过，2=审核不通过
     * @apiSuccess {Integer}   list.checkStatus           审核状态，0=待审核，1=审核通过，2=审核不通过
     * @apiSuccess {Integer}   list.checkFailReason       审核失败原因
     * @apiSuccess {String}    list.createTime            创建时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "sendType" : 1,
     *                  "typeId" : 1,
     *                  "typeName" : "因特网",
     *                  "name" : "测试视频001",
     *                  "cover" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "url" : "http://www.qq.com",
     *                  "duration" : "4分32秒",
     *                  "synopsis" : "我的视频简介",
     *                  "playNum" : 245,
     *                  "regionNames" : "海淀区,崇文区",
     *                  "startTime" : "1476843473471",
     *                  "endTime" : "1476843473472",
     *                  "price" : 3,
     *                  "count" : 1000,
     *                  "isShopping" : 0,
     *                  "recordStatus" : 0,
     *                  "recordContent" : "",
     *                  "checkStatus" : 0,
     *                  "checkFailReason" : "",
     *                  "createTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/video/list", method = RequestMethod.POST)
    public void videoList(HttpServletResponse response, Integer companyUserId, Integer status, Integer pageNum, Integer pageSize) {
        try {
            Page<VideoVo> page = videoService.iPageForCompany(companyUserId, status, pageNum, pageSize);
            Map<String, Object> dataMap = JsonUtil.fitting(page);
            String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap));
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/companyUser/video/recordList 6、视频投放记录列表
     * @apiVersion 0.0.1
     * @apiName companyUser.videoRecordList
     * @apiGroup companyUser
     *
     * @apiDescription 视频投放记录列表
     *
     * @apiParam   {Integer}   videoId                    视频ID                （必填）
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    视频投放记录ID
     * @apiSuccess {String}    list.regionNames           投放区域名称，中间用英文逗号隔开
     * @apiSuccess {String}    list.startTime             开始时间
     * @apiSuccess {String}    list.endTime               结束时间
     * @apiSuccess {Integer}   list.price                 投放单价
     * @apiSuccess {Integer}   list.count                 投放次数
     * @apiSuccess {Integer}   list.isOnly                用户是否只能领取一次奖励（0：否，1：是）
     * @apiSuccess {Integer}   list.isSend                是否允许用户投递简历（0：否，1：是）
     * @apiSuccess {Integer}   list.recordStatus          投放状态，0=未投放，1=投放中
     * @apiSuccess {Integer}   list.recordContent         投放信息
     * @apiSuccess {String}    list.createTime            创建时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "regionNames" : "海淀区,崇文区",
     *                  "startTime" : "1476843473471",
     *                  "endTime" : "",
     *                  "price" : 3,
     *                  "count" : 1000,
     *                  "isOnly" : 0,
     *                  "isSend" : 0,
     *                  "recordStatus" : 1,
     *                  "recordContent" : "剩余￥400",
     *                  "createTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/video/recordList", method = RequestMethod.POST)
    public void videoRecordList(HttpServletResponse response, Integer videoId, Integer pageNum, Integer pageSize) {
        if (null == videoId) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        Page<VideoRecord> page = videoService.iRecordPageForCompany(videoId, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "video", "regionIds", "createTimeStr", "startTimeStr", "endTimeStr");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/companyUser/video/send 7、投放视频
     * @apiVersion 0.0.1
     * @apiName companyUser.sendVideo
     * @apiGroup companyUser
     *
     * @apiDescription 投放视频
     *
     * @apiParam   {Integer}   videoId                    视频ID                                              （必填）
     * @apiParam   {String}    regionIds                  区域ID，中间用英文逗号隔开
     * @apiParam   {String}    regionNames                区域名称，中间用英文逗号隔开
     * @apiParam   {Long}      startTime                  开始时间，时间戳                                     （必填）
     * @apiParam   {Double}   price                      单价                                                （必填）
     * @apiParam   {Integer}   count                      投放次数                                             （必填）
     * @apiParam   {Integer}   isOnly                     是否限制每位用户只能获取一次奖励，0=否，1=是，默认为0
     * @apiParam   {Integer}   isSend                     是否允许用户投放简历，0=否，1=是，默认为0
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/video/send", method = RequestMethod.POST)
    public void sendVideo(HttpServletResponse response, Integer videoId, String regionIds, String regionNames, Long startTime, Double price, Integer count, Integer isOnly, Integer isSend) {
        try {
            videoService.iSendVideo(videoId, null, regionIds, regionNames, startTime, null, price, count, isOnly, isSend);
            String result = JsonUtil.obj2ApiJson(Result.successApi());
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
        } catch (VideoNotFindException e) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_VIDEO_NOT_FIND)));
        } catch (MoneyShortException e) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_MONEY_SHORT)));
        }
    }

    /**
     * @api {post} /api/companyUser/video/delete 8、删除 or 下架视频
     * @apiVersion 0.0.1
     * @apiName companyUser.deleteVideo
     * @apiGroup companyUser
     *
     * @apiDescription 删除 or 下架视频
     *
     * @apiParam   {Integer}   videoId                    视频ID                         （必填）
     * @apiParam   {Integer}   type                       类型，0=下架，1=删除，默认为0
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{}
     * }
     */
    @RequestMapping(value = "/video/delete", method = RequestMethod.POST)
    public void deleteVideo(HttpServletResponse response, Integer videoId, Integer type) {
        try {
            videoService.iDeleteVideo(videoId, type);
            String result = JsonUtil.obj2ApiJson(Result.successApi());
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
        } catch (VideoNotFindException e) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_VIDEO_NOT_FIND)));
        }
    }

    /**
     * @api {post} /api/companyUser/video/resumeList 9、简历投放记录列表
     * @apiVersion 0.0.1
     * @apiName companyUser.videoResumeList
     * @apiGroup companyUser
     *
     * @apiDescription 简历投放记录列表
     *
     * @apiParam   {Integer}   companyUserId              企业用户ID                （必填）
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    简历ID
     * @apiSuccess {String}    list.videoName             投递视频名称
     * @apiSuccess {String}    list.avatar                简历头像
     * @apiSuccess {String}    list.userName              姓名
     * @apiSuccess {Integer}   list.sex                   性别 0=男，1=女
     * @apiSuccess {Integer}   list.age                   年龄
     * @apiSuccess {Integer}   list.regionId              所在地Id
     * @apiSuccess {String}    list.regionInfo            所在地
     * @apiSuccess {Integer}   list.cityId                户籍Id
     * @apiSuccess {String}    list.cityInfo              户籍名称
     * @apiSuccess {String}    list.mobile                手机号
     * @apiSuccess {String}    list.email                 电子邮件
     * @apiSuccess {String}    list.nationInfo            民族
     * @apiSuccess {String}    list.schoolName            毕业院校
     * @apiSuccess {String}    list.educationInfo         学历
     * @apiSuccess {String}    list.disciplineInfo        专业
     * @apiSuccess {String}    list.situationInfo         在校情况
     * @apiSuccess {String}    list.honorInfo             个人荣誉
     * @apiSuccess {String}    list.skillInfo             工作经历
     * @apiSuccess {String}    list.createTime            创建时间
     * @apiSuccess {String}    list.updateTime            更新时间
     * @apiSuccess {Object}    list.imageList             证书列表
     * @apiSuccess {Integer}   list.imageList.id          证书id
     * @apiSuccess {String}    list.imageList.url         证书url
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "videoName" : "电子商务专员/互联网运营专员招聘",
     *                  "avatar" : "http://www.qq.com",
     *                  "userName" : "张莹共",
     *                  "sex" : 1,
     *                  "age" : 23,
     *                  "regionId" : "32",
     *                  "regionInfo" : "湖北武汉",
     *                  "cityId" : "32",
     *                  "cityInfo" : "湖北武汉",
     *                  "mobile" : "15866325478",
     *                  "email" : "4126654321@qq.com",
     *                  "nationInfo" : "汉族",
     *                  "schoolName" : "上海复旦大学",
     *                  "educationInfo" : "本科",
     *                  "disciplineInfo" : "机械电子",
     *                  "situationInfo" : "良好",
     *                  "honorInfo" : "良好",
     *                  "skillInfo" : "打完老板跑路",
     *                  "createTime" : "1476843673494",
     *                  "updateTime" : "1476843673494",
     *                  "imageList": [
     *                      {
     *                          "id": 1,
     *                          "url": "http://ogbbsi37j.bkt.clouddn.com/Fj-I92vTFabzuRlyCtL8NAIUVZdC"
     *                      },
     *                      {
     *                          "id": 2,
     *                          "url": "http://ogbbsi37j.bkt.clouddn.com/Fj-I92vTFabzuRlyCtL8NAIUVZdC"
     *                      }
     *                  ]
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/video/resumeList", method = RequestMethod.POST)
    public void videoResumeList(HttpServletResponse response, Integer companyUserId, Integer pageNum, Integer pageSize) {
        if (null == companyUserId) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        Page<UserResumeVo> page = videoService.iResumePageForVideo(companyUserId, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "userResume");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/companyUser/statData 10、基本数据统计
     * @apiVersion 0.0.1
     * @apiName companyUser.statData
     * @apiGroup companyUser
     *
     * @apiDescription 基本数据统计
     *
     * @apiParam   {Integer}   companyUserId                           企业用户ID        （必填）
     * @apiParam   {Integer}   index                                   今日点击排行排名，不传默认为前四名
     *
     * @apiSuccess {Object}    statDataInfo
     * @apiSuccess {Integer}   statDataInfo.allCount                   今日总点击数
     * @apiSuccess {Object}    statDataInfo.clickList                  今日点击排行
     * @apiSuccess {String}    statDataInfo.clickList.name             视频名称
     * @apiSuccess {Integer}   statDataInfo.clickList.count            点击量
     * @apiSuccess {Integer}   statDataInfo.allMoney                   账户总支出
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "statDataInfo": {
     *              "allCount": 121,
     *              "clickList":[
     *                  {
     *                      "name": "金融外企电话客服实习生",
     *                      "count": 210
     *                  },
     *                  {
     *                      "name": "金融外企电话客服实习生",
     *                      "count": 202
     *                  }
     *              ],
     *              "allMoney": 5555
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/statData", method = RequestMethod.POST)
    public void statData(HttpServletResponse response, Integer companyUserId, Integer index) {
        if (null == companyUserId) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        String result = JsonUtil.obj2ApiJson(Result.successInfoApi(videoService.iFindInfoByCompanyUserId(companyUserId, index), "statDataInfo"), "content");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/companyUser/statVideoData 11、投放数据统计
     * @apiVersion 0.0.1
     * @apiName companyUser.statVideoData
     * @apiGroup companyUser
     *
     * @apiDescription 投放数据统计
     *
     * @apiParam   {Integer}   companyUserId                           企业用户ID        （必填）
     * @apiParam   {Integer}   index                                   周期，不传默认为今天
     *
     * @apiSuccess {Object}    statDataInfo
     * @apiSuccess {Object}    statDataInfo.clickList                  点击量列表
     * @apiSuccess {String}    statDataInfo.clickList.name             日期（时间）
     * @apiSuccess {Integer}   statDataInfo.clickList.count            点击量
     * @apiSuccess {Integer}   statDataInfo.moneyList                  消耗金额列表
     * @apiSuccess {String}    statDataInfo.moneyList.name             日期（时间）
     * @apiSuccess {Integer}   statDataInfo.moneyList.count            消耗金额
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "statData": {
     *              "clickList":[
     *                  {
     *                      "name": "7-18",
     *                      "count": 210
     *                  },
     *                  {
     *                      "name": "7-19",
     *                      "count": 202
     *                  }
     *              ],
     *              "moneyList":[
     *                  {
     *                      "name": "7-18",
     *                      "count": 210
     *                  },
     *                  {
     *                      "name": "7-19",
     *                      "count": 202
     *                  }
     *              ]
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/statVideoData", method = RequestMethod.POST)
    public void statVideoData(HttpServletResponse response, Integer companyUserId, Integer index) {
        if (null == companyUserId) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        String result = JsonUtil.obj2ApiJson(Result.successInfoApi(videoService.iFindInfoByCompanyUserIdAndIndex(companyUserId, index, null), "statData"), "content", "sexList", "ageList", "provinceList", "cityList");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/companyUser/statUserData 12、用户属性分析
     * @apiVersion 0.0.1
     * @apiName companyUser.statUserData
     * @apiGroup companyUser
     *
     * @apiDescription 用户属性分析
     *
     * @apiParam   {Integer}   companyUserId                           企业用户ID        （必填）
     *
     * @apiSuccess {Object}    statDataInfo
     * @apiSuccess {Object}    statDataInfo.sexList                    性别列表
     * @apiSuccess {String}    statDataInfo.clickList.name             名称
     * @apiSuccess {Integer}   statDataInfo.clickList.count            数量
     * @apiSuccess {Object}    statDataInfo.ageList                    年龄列表
     * @apiSuccess {String}    statDataInfo.clickList.name             名称
     * @apiSuccess {Integer}   statDataInfo.clickList.count            数量
     * @apiSuccess {Object}    statDataInfo.provinceList               性别列表
     * @apiSuccess {String}    statDataInfo.clickList.name             名称
     * @apiSuccess {Integer}   statDataInfo.clickList.count            数量
     * @apiSuccess {Object}    statDataInfo.cityList                   城市列表
     * @apiSuccess {String}    statDataInfo.clickList.name             名称
     * @apiSuccess {Integer}   statDataInfo.clickList.count            数量
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "statData": {
     *              "sexList":[
     *                  {
     *                      "name": "7-18",
     *                      "count": 210
     *                  },
     *                  {
     *                      "name": "7-19",
     *                      "count": 202
     *                  }
     *              ],
     *              "ageList":[
     *                  {
     *                      "name": "7-18",
     *                      "count": 210
     *                  },
     *                  {
     *                      "name": "7-19",
     *                      "count": 202
     *                  }
     *              ],
     *              "provinceList":[
     *                  {
     *                      "name": "7-18",
     *                      "count": 210
     *                  },
     *                  {
     *                      "name": "7-19",
     *                      "count": 202
     *                  }
     *              ],
     *              "cityList":[
     *                  {
     *                      "name": "7-18",
     *                      "count": 210
     *                  },
     *                  {
     *                      "name": "7-19",
     *                      "count": 202
     *                  }
     *              ]
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/statUserData", method = RequestMethod.POST)
    public void statUserData(HttpServletResponse response, Integer companyUserId) {
        String result = JsonUtil.obj2ApiJson(Result.successInfoApi(appUserService.getStatUserData(companyUserId), "statData"), "count", "clickList", "moneyList");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/companyUser/video/info 13、视频详情
     * @apiVersion 0.0.1
     * @apiName companyUser.videoInfo
     * @apiGroup companyUser
     *
     * @apiDescription 视频详情
     *
     * @apiParam   {Integer}   videoId                         视频Id                （必填）
     *
     * @apiSuccess {Integer}   videoInfo.id                    视频ID
     * @apiSuccess {Integer}   videoInfo.sendType              投放形式，1=一般形式，2=红包形式，3=其他形式，4=免费形式
     * @apiSuccess {Integer}   videoInfo.typeId                视频分类ID
     * @apiSuccess {String}    videoInfo.typeName              视频分类名称
     * @apiSuccess {Integer}   videoInfo.name                  视频名称
     * @apiSuccess {String}    videoInfo.cover                 封面图
     * @apiSuccess {String}    videoInfo.url                   视频链接
     * @apiSuccess {String}    videoInfo.duration              时长
     * @apiSuccess {String}    videoInfo.synopsis              简介
     * @apiSuccess {Integer}   videoInfo.playNum               播放量
     * @apiSuccess {String}    videoInfo.regionNames           投放区域名称，中间用英文逗号隔开
     * @apiSuccess {String}    videoInfo.startTime             开始时间
     * @apiSuccess {String}    videoInfo.endTime               结束时间
     * @apiSuccess {Integer}   videoInfo.price                 投放单价
     * @apiSuccess {Integer}   videoInfo.count                 投放次数
     * @apiSuccess {Integer}   videoInfo.isShopping            上架状态，0=下架，1=上架
     * @apiSuccess {Integer}   videoInfo.recordStatus          投放状态，0=未投放，1=投放中
     * @apiSuccess {Integer}   videoInfo.recordContent         投放信息
     * @apiSuccess {Integer}   videoInfo.checkStatus           审核状态，0=待审核，1=审核通过，2=审核不通过
     * @apiSuccess {Integer}   videoInfo.checkStatus           审核状态，0=待审核，1=审核通过，2=审核不通过
     * @apiSuccess {Integer}   videoInfo.checkFailReason       审核失败原因
     * @apiSuccess {String}    videoInfo.createTime            创建时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "videoInfo": {
     *                  "id" : 1,
     *                  "sendType" : 1,
     *                  "typeId" : 1,
     *                  "typeName" : "因特网",
     *                  "name" : "测试视频001",
     *                  "cover" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "url" : "http://www.qq.com",
     *                  "duration" : "4分32秒",
     *                  "synopsis" : "我的视频简介",
     *                  "playNum" : 245,
     *                  "regionNames" : "海淀区,崇文区",
     *                  "startTime" : "1476843473471",
     *                  "endTime" : "1476843473472",
     *                  "price" : 3,
     *                  "count" : 1000,
     *                  "isShopping" : 0,
     *                  "recordStatus" : 0,
     *                  "recordContent" : "",
     *                  "checkStatus" : 0,
     *                  "checkFailReason" : "",
     *                  "createTime" : "1476843673494"
     *              }
     *      }
     * }
     */
    @RequestMapping(value = "/video/info", method = RequestMethod.POST)
    public void videoInfo(HttpServletResponse response, Integer videoId) {
        try {
            VideoVo video = videoService.iFindOneForCompany(videoId);
            String result = JsonUtil.obj2ApiJson(Result.successInfoApi(video, "videoInfo"));
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/companyUser/addMoney 14、充值
     * @apiVersion 0.0.1
     * @apiName companyUser.addMoney
     * @apiGroup companyUser
     *
     * @apiDescription 充值
     *
     * @apiParam   {Integer}   companyUserId                    企业用户ID                         （必填）
     * @apiParam   {Double}    money                            金额                              （必填）
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "orderNum" : 1
     *      }
     * }
     */
    @RequestMapping(value = "/addMoney", method = RequestMethod.POST)
    public void addMoney(HttpServletResponse response, Integer companyUserId, Double money) {
        try {
            String result = JsonUtil.obj2ApiJson(Result.successInfoApi(companyUserGainService.addMoney(companyUserId, money), "orderNum"));
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
        }
    }
}
